﻿#ifndef AUDIOPLAYTHREAD_H
#define AUDIOPLAYTHREAD_H

#include <QAudioOutput>
#include <QThread>

class AudioPlayThread : public QThread
{
    Q_OBJECT
public:
    explicit AudioPlayThread(QObject *parent = nullptr);
    ~AudioPlayThread();
    void stop();

    void setPlayParam(uint16_t m_headerLen,uint64_t fileDataSize,uint32_t sampleRate,uint16_t channleNumber,uint16_t bitsPerSample);
    void setAudioFilePath(const QString &value);
    void setPlayBeginEnd(uint64_t playStartIndex,uint64_t playStopIndex);
    void setPlayNowIndex(uint64_t nowIndex);
    void setLoopPlay(bool value);

signals:
    void signal_playState(bool state);
    void signal_playIndex(uint64_t index);
private:
    bool isRun;
    QString audioFilePath;//数据文件路径

    bool setParamed;//注入参数
    //播放器相关参数
    uint16_t headerLen;//文件头长度
    uint64_t fileDataSiz;//文件数据长度
    uint32_t sampleRate;//采样率
    uint16_t channleNumber;//通道数量
    uint16_t bitsPerSample;//采样位数

    uint64_t playStartIndex;
    uint64_t playStopIndex;
    uint64_t playNowIndex;

    bool loopPlay;//循环播放
    //================语音播放器
    QAudioOutput *audioOut;
    QIODevice *audio;
protected:
    void run() override;

};

#endif // AUDIOPLAYTHREAD_H
